package com.zhang.servlet.album;

import com.zhang.util.DBUtil;
import com.zhang.util.Log;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @author happy
 **/
@WebServlet("/studio/album/publish.do")
public class PublishDoServlet extends HttpServlet {
    @Override
    @SneakyThrows
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        // TODO:验证专辑是否属于用户
        String aid = req.getParameter("aid");
        try (Connection c = DBUtil.connection()){
            String sql = "update albums set state = 2 where aid = ?";
            try(PreparedStatement ps = c.prepareStatement(sql)){
                ps.setString(1,aid);
                ps.executeUpdate();
                Log.println("执行SQL"+ps);
            }
        }
        resp.sendRedirect("/studio/album/list.html");
    }
}